import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_fun_zjversion/config/resource_manager.dart';
enum ImageType{
  normal,
  random,
  assets
}


class WrapperImage extends StatelessWidget {
  final String url;
  final double width;
  final double height;
  final BoxFit fit;
  final ImageType imageType;

  WrapperImage({@required this.url, @required this.width, @required this.height, this.fit :BoxFit.cover, this.imageType :ImageType.normal});

  @override
  Widget build(BuildContext context) {
    return CachedNetworkImage(
      imageUrl: imageUrl,
      width: width,
      height: height,
      fit: fit,
      placeholder: (ctx,_)=>ImageHelper.placeHolder(width: width,height: height),
      errorWidget: (ctx,str,_)=>ImageHelper.error(width: width,height: height),
    );
  }

  String get imageUrl {
    switch (imageType) {
      case ImageType.random:
        return ImageHelper.randomUrl(
            key: url, width: width.toInt(), height: height.toInt());
      case ImageType.assets:
        return ImageHelper.wrapAssets(url);
      case ImageType.normal:
        return url;
    }
    return url;
  }
}